<template>
  <div
    v-if="isShow"
    class="toolbar-menu"
    :style="{ width: `${width}px` }"
    :class="`menu-size${size}`"
  >
    <div v-for="(item, index) in menuList" :key="index">
      <div v-if="item.style === 'divider'" class="toolbar-menu-divider" />
      <div
        v-else-if="item.style === 'item' && item.icon"
        class="dis-flex menu-item"
        @click="menuClick(item.type)"
      >
        <div
          class="menu-icon mt-10 ml-5 mr-5"
          :class="item.icon"
          @click="menuClick(item.type)"
        />
        {{ item.title }}
      </div>
      <div v-else class="menu-item" @click="menuClick(item.type)">
        {{ item.title }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MenuList',
  props: {
    menuList: {
      type: Array,
      required: true
    },
    callback: {
      type: Function,
      required: true
    },
    width: {
      type: Number,
      default: 100
    },
    size: {
      type: Number,
      default: 16
    }
  },
  data() {
    return {
      isShow: false
    };
  },
  methods: {
    show() {
      this.isShow = true;
    },
    hide() {
      this.isShow = false;
    },
    menuClick(type) {
      this.callback(type);
    }
  }
};
</script>

<style lang="scss" scopde>
.toolbar-menu {
  background: #fafafa;
  border: 1px solid #a7a7a7;
}
.toolbar-menu-divider {
  width: 100%;
  border-bottom: 1px solid #a7a7a7;
}
.menu-item {
  height: 36px;
  line-height: 36px;
  border: 1px solid transparent;

  &:hover {
    border: 1px solid #0099ff;
  }
}
.menu-size16 {
  font-size: 14px;

  .menu-icon {
    width: 16px;
    height: 16px;
  }
}
.menu-size24 {
  font-size: 16px;

  .menu-icon {
    width: 24px;
    height: 24px;
    background-repeat: no-repeat;
  }
}
</style>
